package com.demo.service;

import com.demo.dto.Teacherdto;

import java.util.ArrayList;
import java.util.List;

public class TeacherService {
    private List<Teacherdto> list;

    public List<Teacherdto> getAllTeacherdto() {
        if (list == null) {
            this.list = new ArrayList<>();
        } else {
            for (int i = 0; i < this.list.size(); i++) {
                Teacherdto Teacherdto = this.list.get(i);
                //System.out.println("老师ID+"+Teacherdto.getId()+"老师姓名+"+Teacherdto.getName()+"老师年龄"+Teacherdto.getAge());
            }
        }
        System.out.println("一共有" + this.list.size() + "名老师");
        return list;
    }

    public boolean addTeacherdto(Teacherdto teacherdto) {
        this.list.add(teacherdto);
        System.out.println("添加了一个学生===" + teacherdto.getName());
        return false;
    }

    public boolean updateTeacherdto(int id, Teacherdto teacherdto) {
        boolean flag = false;
        try {
            int count = 0;
            for (int i = 0; i < this.list.size(); i++) {
                Teacherdto Teacherdto1 = this.list.get(i);
                if (id == Teacherdto1.getId()) {
                    Teacherdto1.setName(teacherdto.getName());
                    Teacherdto1.setAge(teacherdto.getAge());
                } else {
                    count++;
                }
                if (count == this.list.size()) {
                    System.out.println("未找到修改的人");
                }
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }
    public Teacherdto quert(int id){
        Teacherdto teacherdto1 = null;
        try {
            for (int i = 0; i <this.list.size() ; i++) {
                teacherdto1 =this.list.get(i);
                if (id == teacherdto1.getId()) {

                    break;
                }

            }

        }catch (Exception ex){
            ex.printStackTrace();
        }
        return teacherdto1;
    }

    public boolean removeTeacherdto(int id) {
        this.list.remove(id);
        return true;
    }
}